package edu.zqu.instructionalMatters.project.util;

import edu.zqu.instructionalMatters.project.VO.CurriculumResultVO;
import edu.zqu.instructionalMatters.project.entity.Calendar;
import edu.zqu.instructionalMatters.project.entity.CurriculumResult;
import edu.zqu.instructionalMatters.project.entity.CurriculumResultStatus;
import edu.zqu.instructionalMatters.project.entity.TimeTable;
import edu.zqu.instructionalMatters.project.mapper.CalendarMapper;
import edu.zqu.instructionalMatters.project.mapper.CurriculumMapper;
import edu.zqu.instructionalMatters.project.mapper.CurriculumResultStatusMapper;
import edu.zqu.instructionalMatters.project.mapper.TimeTableMapper;
import edu.zqu.instructionalMatters.project.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author 何文东
 * @Date 2020/7/25 14:55
 * @Description:
 * @Version 1.0
 */
@Component
public class CurriculumResultUtil {

    @Autowired
    private CollegeService collegeService;

    @Autowired
    private UserService userService;

    @Autowired
    private CurriculumResultStatusMapper curriculumResultStatusMapper;

    @Autowired
    private CourseService courseService;

    @Autowired
    private SchoolService schoolService;

    @Autowired
    private CalendarMapper calendarMapper;

    @Autowired
    private TimeTableMapper timeTableMapper;

    @Autowired
    private CurriculumMapper curriculumMapper;

    @Autowired
    private InstructionClassService instructionClassService;

    @Autowired
    private FieldService fieldService;

    public CurriculumResultVO curriculumResultUtil(CurriculumResult curriculumResult) {

        CurriculumResultVO curriculumResultVO = new CurriculumResultVO();                                                              //初始化VO
        BeanUtils.copyProperties(curriculumResult, curriculumResultVO);                                                                 //对象复制赋值

        String collegeName = collegeService.getCollegeName(curriculumResult.getCollegeId());                                           //获取学校名称
        curriculumResultVO.setCollegeName(collegeName);                                                                                //学校名称

        String schoolName = schoolService.getSchoolName(curriculumResult.getSchoolId());                                               //获取校区名称
        curriculumResultVO.setSchoolName(schoolName);                                                                                  //校区名称

        CurriculumResultStatus curriculumResultStatus = curriculumResultStatusMapper.selectById(curriculumResult.getStatusId());       //获取执行结果对象
        curriculumResultVO.setStatusName(null);                                                                                        //执行结果名称null
        if (curriculumResultStatus != null) {
            curriculumResultVO.setStatusName(curriculumResultStatus.getName());                                                        //执行结果名称
        }

        Calendar calendar = calendarMapper.selectById(curriculumResult.getCalendarId());                                               //获取校历对象
        curriculumResultVO.setCalendarDate(null);                                                                                      //校历日期null
        if (calendar != null) {
            curriculumResultVO.setCalendarDate(calendar.getTheDate().toString());                                                      //校历日期
        }

        TimeTable timeTable = timeTableMapper.selectById(curriculumResult.getTimeTableId());                                           //获取作息表对象
        curriculumResultVO.setTimeTableName(null);                                                                                     //作息名称null
        if (timeTable != null) {
            curriculumResultVO.setTimeTableName(timeTable.getName());                                                                  //作息名称
        }

        String instructionClassName = instructionClassService.getInstructionClassName(curriculumResult.getInstructionClassId());       //授课班级名称
        curriculumResultVO.setInstructionClassName(instructionClassName);                                                              //授课班级名称

        String courseName = courseService.getCourseName(curriculumMapper.selectById(curriculumResult.getCurriculumId()).getCourseId());//获取课程名称
        curriculumResultVO.setCourseName(courseName);                                                                                  //课程名称

        String teacherName = userService.getUserName(curriculumResult.getTeacherId());                                                 //获取教师姓名
        curriculumResultVO.setTeacherName(teacherName);                                                                                //教师名称

        String fieldName = fieldService.getFieldName(curriculumResult.getFieldId());                                                   //获取场地名称
        curriculumResultVO.setFieldName(fieldName);                                                                                    //场地名称

        return curriculumResultVO;                                                                                                     //返回
    }
}
